package com.cskaoyan.controller.admin;

import com.cskaoyan.bean.bo.OrderListBO;
import com.cskaoyan.bean.bo.OrderRefundBO;
import com.cskaoyan.bean.bo.OrderShipBO;
import com.cskaoyan.bean.vo.OrderDetailVO;
import com.cskaoyan.bean.vo.OrderListVO;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.service.OrderService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *@author: ycb
 *@description: 订单管理
 *@time: 2021/7/8 21:31
 *
 */
@RestController
@RequestMapping("admin/order")
public class OrderController {

    @Autowired
    OrderService orderService;

    /**
     * @Author ycb
     * @description: 获得订单列表
     * @Date 10:22 2021/7/9
     * url:  http://localhost:8083/admin/order/list?page=1&limit=20&sort=add_time&order=desc
     */
    @RequestMapping("list")
    @RequiresPermissions("admin:order:list")
    public BaseRespVo list(OrderListBO listBO){
        OrderListVO orderListVO = orderService.getList(listBO);
        return BaseRespVo.ok(orderListVO);
    }

    /**
     * @Author ycb
     * @description: 获取订单详情
     * @Date 10:44 2021/7/9
     * url:http://182.92.235.201:8083/admin/order/detail?id=20
     */
    @RequestMapping("detail")
    @RequiresPermissions("admin:order:read")
    public BaseRespVo detail(Integer id){
       OrderDetailVO orderDetailVO = orderService.getOrderDetail(id);
       return BaseRespVo.ok(orderDetailVO);
    }

    /**
     * @Author ycb
     * @description: 订单退款
     * @Date 11:35 2021/7/9
     * url:   http://182.92.235.201:8083/admin/order/refund
     */
    @RequestMapping("refund")
    @RequiresPermissions("admin:order:refund")
    public BaseRespVo refund(@RequestBody OrderRefundBO refundBO) {
        orderService.refundMoney(refundBO);
        return BaseRespVo.ok();
    }

    
    /**
     * @Author ycb
     * @description: 订单发货
     * @Date 11:50 2021/7/9
     * url:      http://182.92.235.201:8083/admin/order/ship
     */
    @RequestMapping("ship")
    @RequiresPermissions("admin:order:ship")
    public BaseRespVo ship(@RequestBody OrderShipBO shipBO){
        Integer effectRows = orderService.orderShip(shipBO);
        if (effectRows > 0){
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail("输入参数不对");
    }

    @RequestMapping("reply")
    public BaseRespVo reply() {
        BaseRespVo baseRespVo = new BaseRespVo();
        baseRespVo.setData("成功");
        baseRespVo.setErrno(0);
        return baseRespVo;
    }

}